
import com.etop.weibo.beans.Say;
import com.etop.weibo.dao.DAOFactory;
import com.etop.weibo.dao.SayDao;
import com.etop.weibo.dto.UserSayDTO;
import com.etop.weibo.util.HibernateUtil;
import java.util.Date;
import java.util.List;
import org.hibernate.Session;
import org.junit.Test;

/**
 *
 * @author jansing
 */
public class SayCRUD {
    public void update01(){
        Say say = DAOFactory.getSayDao().load(1);
        say.setPraise(33);
        DAOFactory.getSayDao().update(say);
    }
    
    @Test
    public void testPraise(){
        String hql = new String("update Say set praise=:praise where id=:id");
        Session session = null;
        session = HibernateUtil.openSession();
        session.beginTransaction();
        session.createQuery(hql)
                .setString("praise", "praise+1")
                .setInteger("id", 4)
                .executeUpdate();
        session.getTransaction().commit();
        session.close();
                
    
    }
    
    public void deleteAll01(){
        new SayDao().deleteAll(5);
    }
    public void delete01(){
        DAOFactory.getSayDao().delete(40);
    }
    
    public void list02(){
        List<UserSayDTO> list = DAOFactory.getSayDao().list(1);
        for(UserSayDTO s : list){
            System.out.println(s.getUserId() + " : " + s.getWhat());
        }
    }
    
//    public void list01(){
//        List<UserSayDTO> list = DAOFactory.getSayDao().list();
//        for(UserSayDTO say : list){
//            System.out.println(say.getUserId() + " : " + say.getWhat());
//        }
//                
//    }
    
    public void load01(){
        Say say = DAOFactory.getSayDao().load(50);
//        System.out.println(say.getUserId() + " : " + say.getWhat());
        System.out.println(say);
    }
    
    public void Add01(){
        for(int i=0; i<30;i++){
        Say say = new Say();
        say.setCreateTime(new Date());
        say.setUserId(1);
        say.setWhat("查询在计科系的男生：select t4.name,t1.* from t_stu t1 join t_cla t2 on (t1.cla_id=t2.id) join t_spe t3 on(t2.spe_id=t3.id) join t_dep t4 on(t3.dep_id=t4.id) where t4.name='计科系';");
        say.setPraise(66);
        DAOFactory.getSayDao().add(say);
        }
    }
}
